<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-merchantFeedback-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">内容：</label>
				<div class="col-sm-9">
			    	<textarea type="text" name="content" class="form-control" placeholder="请输入内容">
			    	</textarea>
		    	</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">上传图片：</label>
				<div class="col-sm-8">
					 <input type="file" class="form-control" accept="image/*" id="img_change" />
					  <!-- 传图片地址 -->
					  <input id="imgUrl" name="imgUrl" style="display: none;">
					  <input id="status" name="status" value="0" style="display: none;">
					  <input id="merchantName" name="merchantName" value="畅联盟官方发表" style="display: none;">
					  <input id="merchantId" name="merchantId" value="1" style="display: none;">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">已上传图片：</label>
				<div class="col-sm-8" id="imgParentDiv">
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "system/merchantFeedback"
		$("#form-merchantFeedback-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-merchantFeedback-add').serialize());
	        }
	    }
		
		$(function(){
			//文件传
			$("#img_change").change(function() {
				/* var $file = $(this);
				var fileObj = $file[0];
				var windowURL = window.URL || window.webkitURL;
				var dataURL;
				var $img = $("#headimg");
				if(fileObj && fileObj.files && fileObj.files[0]){
					dataURL = windowURL.createObjectURL(fileObj.files[0]);
					$img.attr('src',dataURL);
				}else{
					dataURL = $file.val();
					var imgObj = document.getElementById("headimg");
					// 1、在设置filter属性时，元素必须已经存在在DOM树中，动态创建的Node，也需要在设置属性前加入到DOM中，先设置属性再加入，无效；
					// 2、src属性需要像下面的方式添加，上面的两种方式添加，无效；
					imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
					imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;
				}  */
			    var formData = new FormData();
			    formData.append("file",$('#img_change')[0].files[0]);
			    $.ajax({
			        url:prefix+'/uploadMaterial',
			        dataType:'json',
			        type:'POST',
			        async: false,
			        data: formData,
			        processData : false, // 使数据不做处理
			        contentType : false, // 不要设置Content-Type请求头
			        success: function(re){
			            if (re.status == 'SUCCESS') {
			            	var url = re.url;
			            	//
			            	$("#imgParentDiv").append("<img style='width: 100px;height: 100px' src='"+url+"' />&nbsp;&nbsp;");
			            	var imgUrl = $("#imgUrl").val();
			                if(imgUrl==""){
			                	imgUrl = imgUrl+url;
			                }else {
			                	imgUrl=imgUrl+";"+url;
			                }
			            	$("#imgUrl").val(imgUrl);
			            } else {
			            	if(re.msg=="404"){
			            		num1 ++;
			            		mui.toast("图片上传不正确请更换图片",{ duration:'long'});
			            	} else if(re.msg=="505"){
			            		num1++;
			            		 $("#idcard_img1").attr("src",url);
			            	}
			            }
			        },
			        error:function(response){
			        }
			    });
			});
			
			
		})
	</script>
</body>
</html>
